﻿Public Class AddNewBook
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       
    End Sub

    Protected Sub btn_Add_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_Add.Click
        If FileUpload_Bpicture.HasFile Then
            FileUpload_Bpicture.SaveAs(Server.MapPath("BookCovers" & "/" & FileUpload_Bpicture.FileName))
        End If

        Dim sql As String = " INSERT INTO Books (B_Name, B_Author, B_ISBN, B_Price, B_Picture, B_Description) VALUES (@v1, @v2, @v3, v4, @v5, @v6)"
        Dim conn As OleDb.OleDbConnection = New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("DBConnString").ConnectionString)
        Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(sql, conn)
        cmd.Parameters.AddWithValue("@v1", txt_BName.Text)
        cmd.Parameters.AddWithValue("@v2", txt_BAuthor.Text)
        cmd.Parameters.AddWithValue("@v3", txt_B_ISBN.Text)
        cmd.Parameters.AddWithValue("@v4", txt_BPrice.Text)
        cmd.Parameters.AddWithValue("@v4", "BookCovers/" & FileUpload_Bpicture.FileName)
        cmd.Parameters.AddWithValue("@v5", txt_BDescription.Text)
        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()
        cmd.Dispose()
        conn.Dispose()
        Response.Redirect("List.aspx")
    End Sub
    Private Sub PriceValid(sender As Object, args As ServerValidateEventArgs)
        'Return true if the input data is numeric.
            If Not IsNumeric(txt_BPrice.Text) Then
                'Data is not numeric.
                CustomValidator1.ErrorMessage = " please enter valid price "
            End If
    End Sub
End Class